package servlet;

import dao.PinglunDao;
import dao.UserDao;
import javabean.Pinglun;
import javabean.User;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/denglu")
public class DengLu extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public void YDengLu() {}
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String xm=request.getParameter("xm");
        String mm=" ";
        String tp=null;
        String xb=request.getParameter("xb");
        User user=new User(xm,xb,mm,tp);

        List<User> list=null;
        UserDao dao=new UserDao();

        try {list = dao.QueryAll();

        } catch (Exception e) {e.printStackTrace();}

        int f=user.pdListUser(list);

        if(f==1){
            PinglunDao pinglunDao=new PinglunDao();
            List<Pinglun> pinglunList= null;
            try {
                pinglunList = pinglunDao.QueryAll();
            } catch (Exception e) {
                e.printStackTrace();
            }
            request.getSession().setAttribute("xm",xm);
            request.getSession().setAttribute("pinglunList",pinglunList);
            RequestDispatcher rd=request.getRequestDispatcher("denglu_chenggong.jsp");
            rd.forward(request,response);
        }else{

            RequestDispatcher rd=request.getRequestDispatcher("zhuce.jsp");//直接注册。（不是注册用户，无权登录）
            rd.forward(request,response);
        }
    }
}
